package ru.vsu.cs.netcracker;

import java.util.*;

public class SortList {

	public static void main(String[] args) {

		List list = new ArrayList();

		list.add(15);
		list.add(10);
		list.add(20);

		sort(list, true);
		System.out.println(Arrays.toString(list.toArray()));

		System.out.println();

		sort(list, false);
		System.out.println(Arrays.toString(list.toArray()));

	}

	static void sort(List list, final boolean updown) {
		Comparator comparator = new Comparator() {
			public int compare(Object o1, Object o2) {
				if (o1 instanceof String)
					o1 = Integer.parseInt((String) o1);
				if (o2 instanceof String)
					o2 = Integer.parseInt((String) o2);
				if ((Integer) o1 < (Integer) o2) {
					if (updown == true)
						return -1;
					else
						return 1;
				}
				if ((Integer) o1 > (Integer) o2) {
					if (updown == true)
						return 1;
					else
						return -1;
				}
				return 0;
			}
		};

		Collections.sort(list, comparator);

	};
}
